package com.yanqu.road.server.manger.config;

import com.yanqu.road.logic.bussiness.config.TitleBussiness;
import com.yanqu.road.entity.servercenter.TitleInfo;
import com.yanqu.road.server.TempMgr;

import java.util.Map;

public class TitleMgr extends TempMgr {

    private static Map<Integer, TitleInfo> titleInfoMap;

    private static int maxTitleId;

    @Override
    public boolean init() throws Exception {
        return reload();
    }

    @Override
    public boolean stop() {
        return false;
    }

    @Override
    public boolean save() {
        return false;
    }

    @Override
    public boolean reloadConfig() {
        titleInfoMap = TitleBussiness.getTitleInfoMap();
        if (null == titleInfoMap || titleInfoMap.size() == 0) {
            return false;
        }
        int maxId = 0;
        for(TitleInfo titleInfo : titleInfoMap.values()){
            if(titleInfo.getTitleId() > maxId){
                maxId = titleInfo.getTitleId();
            }
        }
        maxTitleId = maxId;
        return true;
    }

    @Override
    public boolean reloadData() throws Exception {
        return true;
    }

    public static TitleInfo getTitleInfo(int titleId) {
        return titleInfoMap.get(titleId);
    }

    public static int getMaxTitleId() {
        return maxTitleId;
    }
}
